/*
 * @Author: zhangxuanjiu 
 * @Date: 2017-08-10 14:59:35 
 * @Last Modified by: zhangxuanjiu
 * @Last Modified time: 2017-08-11 12:41:21
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import initStore from './vuex/initStore'
import routes from './router/router'
import Vuex from 'vuex'
import util from './lib/util'
import Cookies from 'js-cookie'
// import './agent.less'
// import _lodash from 'lodash'
// window._ = _lodash

window.util = util
Vue.use(Vuex)
Vue.use(VueRouter)
window.Cookies = Cookies

const store = initStore()

const Root = {
  template: ` 
    <router-view></router-view>
  `
}

const router = new VueRouter({
  routes
})

const instance = new Vue({
  router,
  store, // 注入到所有子组件
  components: { Root }
})

function getQueryString (name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}
const token = getQueryString('token');
const areaCode = getQueryString('areaCode')
const shareUrl = window.location.href

console.log('token', token)
console.log('areaCode', areaCode)
console.log('shareUrl', shareUrl)
Cookies.set('areaCode', areaCode)
Cookies.set('token', token)
Cookies.set('shareUrl', shareUrl)
store.commit('changeToken', {token})
// store.commit('changeAreaCode', {areaCode})

instance.$mount('#root')